//
//  SEMineAPI.swift
//  SmartEyeForDoctor
//
//  Created by qdsg on 2021/5/7.
//

import Moya

enum SEMineAPI {
    case doctorAuth(id: String, idcard: String, idcardBack: String, card: String)
    /// 设置单次问诊价格
    case setSingleInquiryPrice(id: String, fee: Double)
    /// 获取医生二维码
    case doctorQrCode
}

extension SEMineAPI: TargetType {
    var baseURL: URL {
        return URL(string: SEApiManager.baseUrl)!
    }

    var path: String {
        switch self {
        case .doctorAuth: return "/smarteye/smarteye-base/doctor/authenticate"
        case .setSingleInquiryPrice: return "/smarteye/smarteye-base/doctor/add/fee"
        case .doctorQrCode: return "/smarteye/smarteye-base/doctor/create/qrCode"
        }
    }

    var method: Moya.Method {
        return .post
    }

    var sampleData: Data {
        return "".data(using: .utf8)!
    }

    var task: Task {
        SELog("\(path) \n \(parameters)")
        return .requestParameters(parameters: parameters, encoding: JSONEncoding.default)
    }

    var headers: [String : String]? {
        return SEApiManager.headers
    }

    private var parameters: [String: Any] {
        switch self {
        case let .doctorAuth(id, idcard, idcardBack, card):
            return ["id": id,
                    "cardFrontId": idcard,
                    "cardBackId": idcardBack,
                    "certificateId": card]
        case let .setSingleInquiryPrice(id, fee):
            return ["id": id, "fee": Int(fee)]
        case .doctorQrCode:
            return [:]
        }
    }
}
